home *** CD-ROM | disk | FTP | other *** search
/ SuperHack / SuperHack CD.bin / CODING / 8_16BIT / PICSTART.ZIP / TUTOR.ASM < prev    next >
Encoding:
Assembly Source File  |  1994-08-09  |  2.6 KB  |  85 lines

  1. ;-----------------------------------------------------
  2. ;This universal sample program runs on the following
  3. ;processor types: PIC16C5X, PIC16CXX, and PIC17CXX.
  4. ;
  5. ;Execution starts at instruction 50.
  6. ;The loop routine executes seven times.  
  7. ;       The routines, ReduceA and DoubleB, 
  8. ;       each execute one time for each loop cycle.
  9. ;After the loop executes seven times, the instruction 
  10. ;at location 59 returns the program counter to start.
  11. ;
  12. ;
  13. ;Start initializes:     A = 255, (A decreases to  128)
  14. ;                       B =   1, (B increases to  128)
  15. ;                       C =   7, (C decrements to   0)
  16. ;                       w =   7
  17. ;                    wreg =   7
  18. ;           
  19. ;The sample program calculates values as follows:
  20. ;Cycle #    A (A=A-B)   B (B=B+B)    C (C=C-1)    
  21. ;  0           255           1           7
  22. ;  1           254           2           6
  23. ;  2           252           4           5
  24. ;  3           248           8           4
  25. ;  4           240          16           3
  26. ;  5           224          32           2  
  27. ;  6           192          64           1   
  28. ;  7           128         128           0  
  29. ;
  30. ;Caution:  Enter the device name printed on the probe 
  31. ;          connected to your pod before assembling 
  32. ;          this code.
  33. ;-----------------------------------------------------
  34. ;
  35.         list p=16c64, f=inhx8m  ;Enter device name 
  36.                                 ;printed on the probe
  37.                                 ;connected to your pod.
  38. ;------------------------------------------------------
  39. ;Please define ScratchPadRam here:
  40. ;If you are using PIC16C5X define "ScratchPadRam equ 0x10" 
  41. ;else define "ScratchPadRam equ 0x20"
  42. ;-------------------------------------------------------
  43. ScratchPadRam   equ     0x20
  44. A       equ     ScratchPadRam+0
  45. B       equ     ScratchPadRam+1
  46. C       equ     ScratchPadRam+2
  47. w       equ     0
  48. ;        
  49.         org     0       ;start address 0
  50.         goto    start
  51.         org     0x50
  52. ;
  53. start
  54.         movlw   .255
  55.         movwf   A       ;A=255 start
  56.         movlw   .1
  57.         movwf   B       ;B=1   start
  58.         movlw   .7
  59.         movwf   C       ;C=7   start
  60. loop                    
  61.         call    ReduceA ;run 7 loops
  62.         decfsz  C       ;C=C-1
  63.         goto    loop   
  64.         goto    start   ;initialize
  65. ;
  66. ReduceA                 
  67.         swapf   B
  68.         swapf   B,w
  69.         swapf   B
  70.         subwf   A       ;A=A-B
  71.         call    DoubleB
  72.         retlw   0
  73. ;
  74. DoubleB                 
  75.         swapf   B
  76.         swapf   B,w
  77.         swapf   B
  78.         addwf   B       ;B=B+B
  79.         retlw   0
  80. ;
  81.         end
  82.  
  83.  
  84.  
  85.